﻿using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class ABDepends : ScriptableObject
{
    public List<string> nameList = new List<string>();
    public List<string> dependStrList = new List<string>();
    public List<string[]> dependList = new List<string[]>();

    private bool isInit = false;
    public void AddDepend(string key, string[] depends)
    {
        //此方法打包工具用  不关心效率问题
        int index = nameList.IndexOf(key);
        if (index > -1)
        {
            dependStrList[index] = key + "   " + string.Join(" ", depends);
        }
        else
        {
            nameList.Add(key);
            dependStrList.Add(key + "   " + string.Join(" ", depends));
        }
    }

    public void Init()
    {
        if (!isInit)
        {
            isInit = true;
            for (int i = 0; i < dependStrList.Count; i++)
            {
                int index = nameList[i].Length + 3;
                dependList.Add(dependStrList[i].Substring(index).Split(' '));
            }
            dependStrList.Clear(); dependStrList = null;
        }
    }

    public string[] GetDepends(string key)
    {
        int index = nameList.IndexOf(key);
        if (index > -1)
        {
            return dependList[index];
        }
        return null;
    }
}